<template>
	<view>
		<view class="d_flex d_flex_between d_flex_items_center p-50 borderB" v-if="type">
			<view>
				<view class="f-32 color333 f-wb">车主:{{order.product.nickname}}</view>
				<view class="m-t-20 m-b-20"><u-rate v-model="order.product.star" :disabled="true"></u-rate></view>
				<view class="f-24 color333" @click="call(order.product.mobile)">
					<u-icon name="phone-fill" color="#2979ff" size="28"></u-icon>
					<text class="p-l-10">拨打电话：{{order.product.mobile}}</text>
				</view>
			</view>
			<view>
				<image :src="order.product.avatar" class="w-120 h-120"></image>
			</view>
		</view>
		<view class="d_flex d_flex_between d_flex_items_center p-50 borderB" v-else>
			<view>
				<view class="f-32 color333 f-wb">司机:{{order.consumer.nickname}}</view>
				<view class="m-t-20 m-b-20"><u-rate v-model="order.consumer.star" :disabled="true"></u-rate></view>
				<view class="f-24 color333" @click="call(order.consumer.mobile)">
					<u-icon name="phone-fill" color="#2979ff" size="28"></u-icon>
					<text class="p-l-10">拨打电话：{{order.consumer.mobile}}</text>
				</view>
			</view>
			<view>
				<image :src="order.consumer.avatar" class="w-120 h-120"></image>
			</view>
		</view>
		<view class="w-650 m-50">
			<view class="m-t-30">
				<u-input v-model="value" type="textarea" placeholder="请输入评价内容" :height="300"/>
			</view>
			<view class="d_flex borderB d_flex_items_center p-b-30">
				<text class="color999 m-r-10">请给他打分</text>
				<u-rate :count="count" v-model="starVal"></u-rate>
			</view>
			<u-button type="primary" @click="evaBtn">确认评价</u-button>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				order:{},
				value:"",
				count: 5,
				starVal:5,
				id:"",
				type:0
			}
		},
		onLoad(val){
			console.log(val)
			this.id = val.id
			this.type = Number(val.type)
			this.getInfo(val.id)
		},
		methods:{
			async getInfo(id){
				let result = await this.$request.post('/api/common/orderDetail',{
					oid:id
				})
				console.log(result)
				let data = result.data.data 
				this.order = data.order
			},
			evaBtn(){
				if(this.type == 1){
					this.siji()
				}else{
					this.chezhu()
				}
			},
			async chezhu(){
				let data = await this.$request.post('/api/product/evaluation',{
					oid:this.id,
					score:this.starVal,
					memo:this.value
				})
				console.log(data)
				if(data.data.code === 1){
					uni.showToast({
						title:"评价成功~",
						duration:1500
					})
					setTimeout(()=>{
						uni.navigateBack()
					},1500)
				}else{
					uni.showToast({
						title:"评价失败",
						icon:"none"
					})
				}
			},
			async siji(){
				let data = await this.$request.post('/api/Consumer/evaluation',{
					oid:this.id,
					score:this.starVal,
					memo:this.value
				})
				console.log(data)
				if(data.data.code === 1){
					uni.showToast({
						title:"评价成功~",
						duration:1500
					})
					setTimeout(()=>{
						uni.navigateBack()
					},1500)
				}else{
					uni.showToast({
						title:"评价失败",
						icon:"none"
					})
				}
			},
			call(phone){
				uni.makePhoneCall({
				    phoneNumber: phone 
				});
			}
		}
	}
</script>

<style>
	page{background:#fff;}
</style>
